﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebApplication1
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                DropDownList1.Items.Add("福建");
                DropDownList1.Items.Add("广东");
                DropDownList1.Items.Add("山东");
                DropDownList2.Items.Add("龙岩");
                DropDownList2.Items.Add("厦门");
                DropDownList2.Items.Add("漳州");
            }
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            Literal1.Text = $"欢迎{this.TextBox1.Text}来到我的世界";

            foreach (ListItem item in RadioButtonList1.Items)
            {
                if (item.Selected)
                {
                    Literal2.Text = $"性别{item.Text}";
                }
            }

            string habits = "你的爱好是：";
            for (int i = 0; i < CheckBoxList1.Items.Count; i++)
            {
                if (CheckBoxList1.Items[i].Selected)
                {
                    habits += CheckBoxList1.Items[i].Text + "   ";
                }
            }
            Literal3.Text = habits;

            Literal4.Text = $"省份：{DropDownList1.SelectedValue}";
            Literal5.Text = $"市区：{DropDownList2.SelectedValue}";
            Literal6.Text = $"其他信息：{this.TextBox3.Text}";

            if (FileUpload1.HasFile)
            {
                string fileName = FileUpload1.FileName;
                if (fileName.EndsWith(".jpg") || fileName.EndsWith(".png") || fileName.EndsWith(".jpeg"))
                {
                    string url = Server.MapPath("/img/" + fileName);
                    FileUpload1.SaveAs(url);
                    Image1.ImageUrl = "/img/" + fileName;
                    Image1.Visible = true;
                }
            }
        }
        protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
        {
            string province = DropDownList1.SelectedValue;
            DropDownList2.Items.Clear();

            if (province == "福建")
            {
                DropDownList2.Items.Add("龙岩");
                DropDownList2.Items.Add("厦门");
                DropDownList2.Items.Add("漳州");
            }
            else if (province == "广东")
            {
                DropDownList2.Items.Add("深圳");
                DropDownList2.Items.Add("广州");
                DropDownList2.Items.Add("东莞");
            }
            else
            {
                DropDownList2.Items.Add("荷的曹县牛逼666");
                DropDownList2.Items.Add("济南");
                DropDownList2.Items.Add("临沂");
            }
        }
    }
}